home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / WIN_PRO / DS-1.ZIP;1 / RUNTIME.ZIP / RMEMFIX.RI < prev    next >
Encoding:
Text File  |  1992-02-10  |  2.4 KB  |  101 lines

  1. /*
  2.  * File: rmemfix.ri - memory management functions for fixed regions
  3.  *  Contents: initalloc, reclaim
  4.  */
  5.  
  6. /*
  7.  * Prototype.
  8.  */
  9.  
  10. hidden    novalue reclaim    Params((int region));
  11.  
  12. /*
  13.  * initalloc - initialization routine to allocate memory regions
  14.  */
  15.  
  16. #if COMPILER
  17. novalue initalloc()
  18.    {
  19.    static char dummy[1];    /* dummy static region */
  20.  
  21. #else                    /* COMPILER */
  22. novalue initalloc(codesize)
  23. word codesize;
  24.    {
  25.    static char dummy[1];    /* dummy static region */
  26.  
  27.    if (codesize > (unsigned)MaxBlock)
  28.       error("icode file too large");
  29.    /*
  30.     * Allocate icode region
  31.     */
  32.    if ((code = (char *)AllocReg(codesize)) == NULL)
  33.       error("insufficient memory for icode");
  34. #endif                    /* COMPILER */
  35.  
  36.    /*
  37.     * Set up allocated memory.    The regions are:
  38.   
  39.     *    Static memory region (not used)
  40.     *    Allocated string region
  41.     *    Allocate block region
  42.     *    Qualifier list
  43.     */
  44.  
  45.    statend = statfree = statbase = dummy;
  46. #ifdef MultiRegion
  47.    {
  48.    uword t1, t2;
  49.    t1 = ssize;
  50.    t2 = abrsize;
  51.    curstring = (struct region *)malloc(sizeof(struct region));
  52.    curblock = (struct region *)malloc(sizeof(struct region));
  53.    curstring->size = t1;
  54.    curblock->size = t2;
  55.    }
  56.    curstring->next = curstring->prev = NULL;
  57.    curstring->Gnext = curstring->Gprev = NULL;
  58.    curblock->next = curblock->prev = NULL;
  59.    curblock->Gnext = curblock->Gprev = NULL;
  60. #endif                    /* MultiRegion */
  61.    if ((strfree = strbase = (char *)AllocReg(ssize)) == NULL)
  62.       error("insufficient memory for string region");
  63.    strend = strbase + ssize;
  64.    if ((blkfree = blkbase = (char *)AllocReg(abrsize)) == NULL)
  65.       error("insufficient memory for block region");
  66.    blkend = blkbase + abrsize;
  67.    if ((quallist = (dptr *)AllocReg(qualsize)) == NULL)
  68.       error("insufficient memory for qualifier list");
  69.    equallist = (dptr *)((char *)quallist + qualsize);
  70.    }
  71.  
  72. /*
  73.  * reclaim - reclaim space in the allocated memory regions. The marking
  74.  *   phase has already been completed.
  75.  */
  76.  
  77. static novalue reclaim(region)
  78. int region;
  79.    {
  80.    /*
  81.     * Collect available co-expression blocks.
  82.     */
  83.    cofree();
  84.  
  85.    /*
  86.     * Collect the string space leaving it where it is.
  87.     */
  88.    if (!qualfail)
  89.       scollect((word)0);
  90.  
  91.    /*
  92.     * Adjust the blocks in the block region in place.
  93.     */
  94.    adjust(blkbase,blkbase);
  95.  
  96.    /*
  97.     * Compact the block region.
  98.     */
  99.    compact(blkbase);
  100.    }
  101.